//
//  SecondViewController.m
//  UI07_UINavigationController
//
//  Created by aaaaaa on 16/6/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "ThreeViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"Second";
    
    [self cofigNavigationItem];
    [self createBackButton];
}


- (void)cofigNavigationItem{
    
    /**创建标题视图**/
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"电话"]];
    segment.frame = CGRectMake(100, 10, 100, 30);
    segment.selectedSegmentIndex = 0;
    
    /**指定标题视图**/
    self.navigationItem.titleView = segment;
    [segment release];
    
    /*创建右边的Item*/
    UIBarButtonItem *itemOfRight = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(itemOfRightAction:)];
    UIBarButtonItem *otherItemOfRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(otherItemOfRightAction:)];
    
    self.navigationItem.rightBarButtonItems = @[itemOfRight, otherItemOfRight];
    [itemOfRight release];
    [otherItemOfRight release];
    
    /*隐藏返回按钮*/
//    self.navigationItem.hidesBackButton = YES;
    
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}

- (void)itemOfRightAction:(UIBarButtonItem *)item{
    NSLog(@"next");
    ThreeViewController *threeVc = [[ThreeViewController alloc] init];
    [self.navigationController pushViewController:threeVc animated:YES];
    [threeVc release];
}

- (void)otherItemOfRightAction:(UIBarButtonItem *)item{
    NSLog(@"Edit");
}


- (void)createBackButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(50, 100, 100, 50);
    [button setTitle:@"返回上一页" forState:UIControlStateNormal];
    
    button.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)backAction:(UIButton *)button{
    
    /** 回到上一个控制器**/
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
